<template>
  <div
    class="select-container"
    @click="handleClick"
  >
    <div class="select-header">
      <div class="select-placeholder">{{ modelValue }}</div>

      <span
        class="iconfont"
        :class="{ 'icon-arrow_d': isShow, 'icon-arrow_u': !isShow }"
      ></span>
    </div>

    <div
      class="select-optionTalbe"
      v-show="isShow"
    >
      <slot></slot>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const props = defineProps({
  modelValue: {
    type: [String, Number],
    default: '',
  },
});

const isShow = ref(false);

function handleClick() {
  isShow.value = !isShow.value;
}
</script>

<style scoped>
/* 引入在线iconfont */
@import 'http://at.alicdn.com/t/c/font_4989155_z8w02m19tg8.css';

.select-container {
  position: relative;

  padding: 0 8px;
  width: 60px;
  height: 24px;

  border: 1px solid #666;
  border-radius: 3px;
}
.select-container:hover {
  border: 1px solid #4169e1;
  cursor: pointer;
}

.select-header {
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.select-placeholder {
  font-size: 12px;
}

.iconfont {
  font-size: 12px;
  color: #999;
}

.select-optionTalbe {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 6px;

  width: 60px;
  max-height: 240px;
  padding: 4px 8px;
  background: white;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 2px;
  white-space: nowrap;

  overflow: auto;
}

.select-optionTalbe::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);

  width: 6px;
  height: 6px;
  background: white; /* 背景色与下拉框一致 */
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
}
</style>
